package cn.ll.action;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.web.servlet.ModelAndView;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import cn.ll.ModelAndView.ExcelView;
import cn.ll.po.Connector;
import cn.ll.po.Customer;
import cn.ll.po.Permissions;
import cn.ll.po.User;
import cn.ll.service.ConnectorService;
import cn.ll.service.ContractService;
import cn.ll.service.CustomerService;
import cn.ll.service.TaskService;
import cn.ll.util.SystermUtil;
import cn.ll.vo.LoginUser;

public class ConnectorAction extends Action {

	ConnectorService service = null;

	public void read(HttpServletRequest request, HttpServletResponse response) throws IllegalAccessException,
			InvocationTargetException, NoSuchMethodException {

		String customerid = request.getParameter("customerid");
		String id = request.getParameter("id");
		String by = request.getParameter("by");

		Map cdt = new HashMap();
		if (id != null) {
			cdt.put("id", id);
		}
		if (customerid != null) {
			cdt.put("customerid", customerid);
		}
		if (by != null) {
			cdt.put("by", by);
		}

		List ls = service.read(cdt);
		// ls = this.tranToMapList(ls);
		Map rs = new HashMap();
		rs.put("success", true);
		rs.put("items", ls);
		rtn(rs, request, response);

	}

	public void readForSelect(HttpServletRequest request, HttpServletResponse response) throws IllegalAccessException,
			InvocationTargetException, NoSuchMethodException {

		String customerid = request.getParameter("customerid");
		String id = request.getParameter("id");
		String by = request.getParameter("by");

		Map cdt = new HashMap();
		if (id != null) {
			cdt.put("id", id);
		}
		if (customerid != null) {
			cdt.put("customerid", customerid);
		}
		if (by != null) {
			cdt.put("by", by);
		}

		List ls = service.readForSelect(cdt);
		// ls = this.tranToMapList(ls);
		Map rs = new HashMap();
		rs.put("success", true);
		rs.put("items", ls);
		rtn(rs, request, response);

	}

	/**
	 * 根据状态获得用户列表
	 * 
	 * @param request
	 * @param response
	 */
	public void update(HttpServletRequest request, HttpServletResponse response) {

	}

	public void create(HttpServletRequest request, HttpServletResponse response) throws IllegalAccessException,
			InvocationTargetException {

		Connector connector = new Connector();
		BeanUtils.populate(connector, request.getParameterMap());
		service.create(connector);
	}

	public ConnectorService getService() {
		return service;
	}

	public void setService(ConnectorService service) {
		this.service = service;
	}

}
